<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>骨质疏松风险评估问卷</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            margin-top: 40px;
            margin-bottom: 40px;
        }
        
        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 30px;
            font-size: 2rem;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }
        
        .progress-container {
            margin-bottom: 30px;
            background-color: #ecf0f1;
            border-radius: 5px;
            height: 15px;
            overflow: hidden;
        }
        
        .progress-bar {
            height: 100%;
            background-color: #3498db;
            width: 25%; /* 将根据表单部分来更新 */
            transition: width 0.3s ease;
        }
        
        .section {
            display: none;
            margin-bottom: 30px;
        }
        
        .section.active {
            display: block;
            animation: fadeIn 0.5s;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #2c3e50;
        }
        
        input[type="number"],
        input[type="text"],
        select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            box-sizing: border-box;
        }
        
        .radio-group {
            margin-top: 10px;
        }
        
        .radio-option {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
        }
        
        .radio-option input[type="radio"] {
            margin-right: 10px;
        }
        
        .navigation {
            display: flex;
            justify-content: space-between;
            margin-top: 30px;
        }
        
        button {
            padding: 10px 20px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            min-width: 100px;
        }
        
        button:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(52, 152, 219, 0.3);
        }
        
        button.back {
            background-color: #95a5a6;
        }
        
        button.back:hover {
            background-color: #7f8c8d;
        }
        
        button.submit {
            background-color: #2ecc71;
        }
        
        button.submit:hover {
            background-color: #27ae60;
            box-shadow: 0 4px 8px rgba(46, 204, 113, 0.3);
        }
        
        .required-field {
            color: #e74c3c;
        }
        
        .question-number {
            background-color: #3498db;
            color: white;
            display: inline-block;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            text-align: center;
            line-height: 25px;
            margin-right: 10px;
        }
        
        .section-title {
            font-size: 1.4rem;
            color: #3498db;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }
        
        /* 加载动画 */
        .loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(255, 255, 255, 0.9);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1000;
            flex-direction: column;
        }
        
        .spinner {
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin-bottom: 20px;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .loading-text {
            font-size: 18px;
            color: #2c3e50;
        }
        
        @media (max-width: 768px) {
            .container {
                margin-top: 20px;
                margin-bottom: 20px;
                padding: 15px;
            }
            
            h1 {
                font-size: 1.6rem;
            }
            
            .navigation {
                flex-direction: column;
                gap: 10px;
            }
            
            button {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <!-- 加载动画 -->
    <div class="loading-overlay" id="loadingOverlay">
        <div class="spinner"></div>
        <p class="loading-text">正在分析骨质疏松风险...</p>
    </div>

    <div class="container">
        <h1>骨质疏松风险评估问卷</h1>
        
        <div class="progress-container">
            <div class="progress-bar" id="progressBar"></div>
        </div>
        
        <form id="skeletonForm" action="{{ url_for('skeleton.submit') }}" method="post" onsubmit="return validateForm();">
            <!-- 第一部分：基本信息 -->
            <div class="section active" id="section1">
                <h2 class="section-title">基本信息</h2>
                
                <div class="form-group">
                    <label for="age">年龄 <span class="required-field">*</span></label>
                    <input type="number" id="age" name="age" min="18" max="120" required>
                </div>
                
                <div class="form-group">
                    <label for="gender">性别 <span class="required-field">*</span></label>
                    <select id="gender" name="gender" required>
                        <option value="">请选择</option>
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label for="height">身高(厘米) <span class="required-field">*</span></label>
                    <input type="number" id="height" name="height" min="100" max="250" step="0.1" required>
                </div>
                
                <div class="form-group">
                    <label for="weight">体重(公斤) <span class="required-field">*</span></label>
                    <input type="number" id="weight" name="weight" min="30" max="200" step="0.1" required>
                </div>
                
                <div class="navigation">
                    <div></div> <!-- 占位，保持布局对称 -->
                    <button type="button" onclick="nextSection(1, 2)">下一步</button>
                </div>
            </div>
            
            <!-- 第二部分：骨骼风险因素 -->
            <div class="section" id="section2">
                <h2 class="section-title">骨骼风险因素</h2>
                
                <div class="form-group">
                    <label><span class="question-number">1</span>您是否有过轻微碰撞就导致骨折的经历？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="light_injury_yes" name="light_injury" value="是" required>
                            <label for="light_injury_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="light_injury_no" name="light_injury" value="否">
                            <label for="light_injury_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">2</span>您的父母是否有骨折史？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="parent_fracture_yes" name="parent_fracture" value="是" required>
                            <label for="parent_fracture_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="parent_fracture_no" name="parent_fracture" value="否">
                            <label for="parent_fracture_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">3</span>您是否长期服用激素类药物？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="hormone_medication_yes" name="hormone_medication" value="是" required>
                            <label for="hormone_medication_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="hormone_medication_no" name="hormone_medication" value="否">
                            <label for="hormone_medication_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">4</span>您近年来是否身高变矮超过3厘米？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="height_decrease_yes" name="height_decrease" value="是" required>
                            <label for="height_decrease_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="height_decrease_no" name="height_decrease" value="否">
                            <label for="height_decrease_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="navigation">
                    <button type="button" class="back" onclick="prevSection(2, 1)">上一步</button>
                    <button type="button" onclick="nextSection(2, 3)">下一步</button>
                </div>
            </div>
            
            <!-- 第三部分：生活习惯 -->
            <div class="section" id="section3">
                <h2 class="section-title">生活习惯</h2>
                
                <div class="form-group">
                    <label><span class="question-number">5</span>您是否经常饮酒？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="alcohol_yes" name="alcohol" value="是" required>
                            <label for="alcohol_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="alcohol_no" name="alcohol" value="否">
                            <label for="alcohol_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">6</span>您是否吸烟？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="smoking_yes" name="smoking" value="是" required>
                            <label for="smoking_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="smoking_no" name="smoking" value="否">
                            <label for="smoking_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">7</span>您是否经常腹泻？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="diarrhea_yes" name="diarrhea" value="是" required>
                            <label for="diarrhea_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="diarrhea_no" name="diarrhea" value="否">
                            <label for="diarrhea_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="navigation">
                    <button type="button" class="back" onclick="prevSection(3, 2)">上一步</button>
                    <button type="button" onclick="nextSection(3, 4)">下一步</button>
                </div>
            </div>
            
            <!-- 第四部分：性别特定问题 -->
            <div class="section" id="section4">
                <h2 class="section-title">特定健康状况</h2>
                
                <!-- 女性特定问题 -->
                <div id="femaleQuestions">
                    <div class="form-group">
                        <label><span class="question-number">8</span>您是否在45岁之前绝经？</label>
                        <div class="radio-group">
                            <div class="radio-option">
                                <input type="radio" id="early_menopause_yes" name="early_menopause" value="是">
                                <label for="early_menopause_yes">是</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="early_menopause_no" name="early_menopause" value="否">
                                <label for="early_menopause_no">否</label>
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label><span class="question-number">9</span>您是否超过3个月没有来月经？(非妊娠、哺乳期)</label>
                        <div class="radio-group">
                            <div class="radio-option">
                                <input type="radio" id="no_menstruation_yes" name="no_menstruation" value="是">
                                <label for="no_menstruation_yes">是</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="no_menstruation_no" name="no_menstruation" value="否">
                                <label for="no_menstruation_no">否</label>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 男性特定问题 -->
                <div id="maleQuestions" style="display: none;">
                    <div class="form-group">
                        <label><span class="question-number">8</span>您是否存在阳痿问题？</label>
                        <div class="radio-group">
                            <div class="radio-option">
                                <input type="radio" id="impotence_yes" name="impotence" value="是">
                                <label for="impotence_yes">是</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="impotence_no" name="impotence" value="否">
                                <label for="impotence_no">否</label>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="navigation">
                    <button type="button" class="back" onclick="prevSection(4, 3)">上一步</button>
                    <button type="button" onclick="nextSection(4, 5)">下一步</button>
                </div>
            </div>

            <!-- 第五部分：饮食和户外活动 -->
            <div class="section" id="section5">
                <h2 class="section-title">饮食和户外活动习惯</h2>
                
                <div class="form-group">
                    <label><span class="question-number">11</span>您是否经常没什么胃口，或者因为各种原因（比如牙口不好、消化弱）吃得比同龄人明显少很多？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="poor_appetite_yes" name="poor_appetite" value="是" required>
                            <label for="poor_appetite_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="poor_appetite_no" name="poor_appetite" value="否">
                            <label for="poor_appetite_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">12</span>您是否几乎不喝牛奶、酸奶，也很少吃奶酪、豆腐、豆浆这类食物？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="low_calcium_diet_yes" name="low_calcium_diet" value="是" required>
                            <label for="low_calcium_diet_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="low_calcium_diet_no" name="low_calcium_diet" value="否">
                            <label for="low_calcium_diet_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">13</span>您是否很少到户外活动（比如散步、买菜），或者每次出门都把自己裹得严严实实（帽子、长袖、防晒霜）？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="low_sunlight_yes" name="low_sunlight" value="是" required>
                            <label for="low_sunlight_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="low_sunlight_no" name="low_sunlight" value="否">
                            <label for="low_sunlight_no">否</label>
                        </div>
                    </div>
                </div>

                <div class="navigation">
                    <button type="button" class="back" onclick="prevSection(5, 4)">上一步</button>
                    <button type="button" onclick="nextSection(5, 6)">下一步</button>
                </div>
            </div>

            <!-- 第六部分：用药情况和体重 -->
            <div class="section" id="section6">
                <h2 class="section-title">用药和体重情况</h2>
                
                <div class="form-group">
                    <label><span class="question-number">14</span>您是否因为胃酸多、胃不舒服，长期（比如半年以上）天天吃"拉唑"类的胃药（比如奥美拉唑、兰索拉唑等）？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="long_term_ppi_yes" name="long_term_ppi" value="是" required>
                            <label for="long_term_ppi_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="long_term_ppi_no" name="long_term_ppi" value="否">
                            <label for="long_term_ppi_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">15</span>您是否因为过敏、皮肤病或者癫痫，长期（比如半年以上）在吃某些特定的药物？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="special_medication_yes" name="special_medication" value="是" required>
                            <label for="special_medication_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="special_medication_no" name="special_medication" value="否">
                            <label for="special_medication_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">16</span>您是否一直很瘦，或者最近体重无缘无故掉了不少，现在看起来比同龄人瘦弱很多？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="underweight_yes" name="underweight" value="是" required>
                            <label for="underweight_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="underweight_no" name="underweight" value="否">
                            <label for="underweight_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="navigation">
                    <button type="button" class="back" onclick="prevSection(6, 5)">上一步</button>
                    <button type="button" onclick="nextSection(6, 7)">下一步</button>
                </div>
            </div>
            
            <!-- 第七部分：身体症状和疾病史 -->
            <div class="section" id="section7">
                <h2 class="section-title">身体状况和病史</h2>
                
                <div class="form-group">
                    <label><span class="question-number">17</span>您是否经常感觉腰背隐隐作痛，尤其是在站久了或活动后，但又不是因为明显的扭伤或拉伤？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="back_pain_yes" name="back_pain" value="是" required>
                            <label for="back_pain_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="back_pain_no" name="back_pain" value="否">
                            <label for="back_pain_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">18</span>您自己或者家人有没有觉得您的背没有以前直了，开始有点往前弯（驼背）的趋势？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="forward_bending_yes" name="forward_bending" value="是" required>
                            <label for="forward_bending_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="forward_bending_no" name="forward_bending" value="否">
                            <label for="forward_bending_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">19</span>您是否感觉最近走路不如以前稳当，容易脚下打绊子或者需要扶东西？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="walking_instability_yes" name="walking_instability" value="是" required>
                            <label for="walking_instability_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="walking_instability_no" name="walking_instability" value="否">
                            <label for="walking_instability_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label><span class="question-number">20</span>您以前体检或看病，医生有没有告诉过您甲状腺功能异常（甲亢或甲减）或者甲状旁腺有问题？</label>
                    <div class="radio-group">
                        <div class="radio-option">
                            <input type="radio" id="thyroid_issue_yes" name="thyroid_issue" value="是" required>
                            <label for="thyroid_issue_yes">是</label>
                        </div>
                        <div class="radio-option">
                            <input type="radio" id="thyroid_issue_no" name="thyroid_issue" value="否">
                            <label for="thyroid_issue_no">否</label>
                        </div>
                    </div>
                </div>
                
                <div class="navigation">
                    <button type="button" class="back" onclick="prevSection(7, 6)">上一步</button>
                    <button type="submit" class="submit">提交评估</button>
                </div>
            </div>
        </form>
    </div>

    <script>
        // 更新进度条
        function updateProgressBar(section) {
            const progressBar = document.getElementById('progressBar');
            const progress = (section / 7) * 100;  // 更新为7个部分
            progressBar.style.width = progress + '%';
        }
        
        // 下一部分
        function nextSection(current, next) {
            const currentSection = document.getElementById('section' + current);
            let isValid = true;
            
            // 检查普通输入框和选择框
            const regularInputs = currentSection.querySelectorAll('input[type="text"][required], input[type="number"][required], select[required]');
            regularInputs.forEach(input => {
                if (!input.value) {
                    isValid = false;
                    input.style.borderColor = '#e74c3c';
                } else {
                    input.style.borderColor = '#ddd';
                }
            });
            
            // 检查单选按钮组
            const radioGroupNames = new Set();
            currentSection.querySelectorAll('input[type="radio"][required]').forEach(radio => {
                radioGroupNames.add(radio.name);
            });
            
            radioGroupNames.forEach(groupName => {
                const radios = currentSection.querySelectorAll(`input[name="${groupName}"]`);
                const isGroupChecked = Array.from(radios).some(radio => radio.checked);
                const radioContainer = radios[0].closest('.form-group');
                const isVisible = window.getComputedStyle(radioContainer).display !== 'none';
                
                if (isVisible && !isGroupChecked) {
                    isValid = false;
                    
                    radios.forEach(radio => {
                        radio.parentElement.style.border = '1px solid #e74c3c';
                        radio.parentElement.style.borderRadius = '5px';
                        radio.parentElement.style.padding = '5px';
                    });
                    
                    const questionLabel = radioContainer.querySelector('label');
                    if (questionLabel && !questionLabel.querySelector('.warning-text')) {
                        const warning = document.createElement('span');
                        warning.className = 'warning-text';
                        warning.style.color = '#e74c3c';
                        warning.style.marginLeft = '10px';
                        warning.style.fontSize = '0.9em';
                        warning.textContent = '(请选择)';
                        questionLabel.appendChild(warning);
                    }
                } else if (isGroupChecked) {
                    radios.forEach(radio => {
                        radio.parentElement.style.border = 'none';
                        radio.parentElement.style.padding = '0';
                    });
                    
                    const questionLabel = radioContainer.querySelector('label');
                    const warning = questionLabel.querySelector('.warning-text');
                    if (warning) {
                        questionLabel.removeChild(warning);
                    }
                }
            });
            
            if (!isValid) {
                alert('请填写所有必填项');
                return;
            }
            
            // 如果是从第一部分到第二部分，设置性别特定问题
            if (current === 1 && next === 2) {
                const gender = document.getElementById('gender').value;
                setupGenderQuestions(gender);
            }
            
            // 隐藏当前部分，显示下一部分
            document.getElementById('section' + current).classList.remove('active');
            document.getElementById('section' + next).classList.add('active');
            
            // 更新进度条
            updateProgressBar(next);
            
            // 滚动到页面顶部，提高用户体验
            window.scrollTo(0, 0);
        }
        
        // 上一部分
        function prevSection(current, prev) {
            document.getElementById('section' + current).classList.remove('active');
            document.getElementById('section' + prev).classList.add('active');
            updateProgressBar(prev);
            window.scrollTo(0, 0); // 滚动到顶部
        }
        
        // 根据性别设置特定问题
        function setupGenderQuestions(gender) {
            const femaleQuestions = document.getElementById('femaleQuestions');
            const maleQuestions = document.getElementById('maleQuestions');
            
            if (gender === '女') {
                femaleQuestions.style.display = 'block';
                maleQuestions.style.display = 'none';
                
                // 为女性问题设置必填
                document.querySelectorAll('#femaleQuestions input[type="radio"]').forEach(input => {
                    input.required = true;
                });
                document.querySelectorAll('#maleQuestions input[type="radio"]').forEach(input => {
                    input.required = false;
                    input.checked = false;
                });
            } else {
                femaleQuestions.style.display = 'none';
                maleQuestions.style.display = 'block';
                
                // 为男性问题设置必填
                document.querySelectorAll('#maleQuestions input[type="radio"]').forEach(input => {
                    input.required = true;
                });
                document.querySelectorAll('#femaleQuestions input[type="radio"]').forEach(input => {
                    input.required = false;
                    input.checked = false;
                });
            }
        }
        
        // 表单最终提交前的验证
        function validateForm() {
            let isValid = true;
            const form = document.getElementById('skeletonForm');
            
            // 检查所有必填的文本输入框、数字输入框和下拉框
            const regularInputs = form.querySelectorAll('input[type="text"][required], input[type="number"][required], select[required]');
            regularInputs.forEach(input => {
                if (!input.value) {
                    isValid = false;
                    input.style.borderColor = '#e74c3c';
                } else {
                    input.style.borderColor = '#ddd';
                }
            });
            
            // 检查单选按钮组
            // 获取所有单选按钮组的名称
            const radioGroupNames = new Set();
            form.querySelectorAll('input[type="radio"][required]').forEach(radio => {
                radioGroupNames.add(radio.name);
            });
            
            // 检查每个单选按钮组是否有选择
            radioGroupNames.forEach(groupName => {
                // 获取该组中所有单选按钮
                const radios = form.querySelectorAll(`input[name="${groupName}"]`);
                
                // 检查该组是否有任何一个被选中
                const isGroupChecked = Array.from(radios).some(radio => radio.checked);
                
                // 检查该组是否可见（如果组所在部分被隐藏，则不验证）
                const radioContainer = radios[0].closest('.form-group');
                const isVisible = window.getComputedStyle(radioContainer).display !== 'none';
                
                // 只验证可见的必填单选按钮组
                if (isVisible && !isGroupChecked) {
                    isValid = false;
                    
                    // 为单选按钮组添加错误提示样式
                    radios.forEach(radio => {
                        radio.parentElement.style.border = '1px solid #e74c3c';
                        radio.parentElement.style.borderRadius = '5px';
                        radio.parentElement.style.padding = '5px';
                    });
                    
                    // 找到问题标题并添加红色提示
                    const questionLabel = radioContainer.querySelector('label');
                    if (questionLabel && !questionLabel.querySelector('.warning-text')) {
                        const warning = document.createElement('span');
                        warning.className = 'warning-text';
                        warning.style.color = '#e74c3c';
                        warning.style.marginLeft = '10px';
                        warning.style.fontSize = '0.9em';
                        warning.textContent = '(请选择)';
                        questionLabel.appendChild(warning);
                    }
                } else if (isGroupChecked) {
                    // 已选择，移除任何错误提示
                    radios.forEach(radio => {
                        radio.parentElement.style.border = 'none';
                        radio.parentElement.style.padding = '0';
                    });
                    
                    const questionLabel = radios[0].closest('.form-group').querySelector('label');
                    const warning = questionLabel.querySelector('.warning-text');
                    if (warning) {
                        questionLabel.removeChild(warning);
                    }
                }
            });
            
            if (!isValid) {
                // 阻止表单提交
                alert('请填写所有必填项');
                return false;
            }
            
            // 所有验证通过，显示加载动画
            const loadingOverlay = document.getElementById('loadingOverlay');
            loadingOverlay.style.display = 'flex';
            return true;
        }
        
        // 表单提交时显示加载动画
        function showLoading() {
            // 验证逻辑已移至validateForm函数
            // 无需再次验证，因为表单提交时会自动调用validateForm函数
            return true;
        }
        
        // 初始化进度条
        document.addEventListener('DOMContentLoaded', function() {
            updateProgressBar(1);
            
            // 监听性别选择变化
            document.getElementById('gender').addEventListener('change', function() {
                setupGenderQuestions(this.value);
            });
        });
    </script>
</body>
</html> 